package huanzhao.erp.other.aspect;

import huanzhao.erp.domain.po.Result;
import huanzhao.erp.service.ClearService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author April
 * @version 1.0
 * 2024/7/25 下午1:06
 */
@Aspect
@Component
public class AvoidClearAspect {
    private final ClearService clearService;

    public AvoidClearAspect(ClearService clearService) {
        this.clearService = clearService;
    }

    /**
     * 定义切点
     */
    @Pointcut("@annotation(huanzhao.erp.domain.annotation.AvoidClear)")
    public void pointCut() {
    }

    /**
     * 环绕通知
     */
    @Around("pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        if (clearService.isInBigClear()) {
            return Result.error("大盘库期间，不允许进行该操作");
        }
        return joinPoint.proceed();
    }

}
